import axios from "axios"

export default {
	namespaced: true,
	state: {
		bmiList: [],
	},
	getters: {},
	mutations: {
		SET_BMI_LIST(state, data) {
			state.bmiList = data
		},
	},
	actions: {
		async getBMIList(context) {
			const res = await axios({
				url: "http://yizhanketang.com:1010/api/v1/bmi"
			})
			context.commit("SET_BMI_LIST", res.data)
		},
		async delItem(context, id) {
			await axios({
				method: "DELETE",
				url: `http://yizhanketang.com:1010/api/v1/bmi/${id}`,
			})
			// reload
			context.dispatch("getBMIList")
		},
		async addItem(context, data) {
			const res = await axios({
				method: "POST",
				url: "http://yizhanketang.com:1010/api/v1/bmi",
				data,
			})
			context.dispatch("getBMIList")
			return res
		},
	}
}


